package com.george.es.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

/**
 * <p>
 *  解析token
 * </p>
 *
 * @author GeorgeChan 2019/3/24 19:07
 * @version 1.0
 * @since jdk1.8
 */
public class ParseJwtTest {
    public static void main(String[] args) {
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjMiLCJzdWIiOiLlsI_mmboiLCJpYXQiOjE1NTM0MjY4MTcsImV4cCI6MTU1MzQyNjg3Nywicm9sZSI6ImFkbWluIn0.Yo1B_mWn7cpvHWEjK2OhIUYuZn7bNez5hn6DckVIFlw";
        // 解析token
        Claims claims = Jwts.parser().setSigningKey("george").parseClaimsJws(token).getBody();
        System.out.println("id: " + claims.getId());
        System.out.println("登录人： " + claims.getSubject());
        System.out.println("登录时间： " + claims.getIssuedAt());
        System.out.println("过期时间： "+claims.getExpiration());
        System.out.println("当前角色： " + claims.get("role"));
    }
}
